<template>
    <el-main>
        <el-table
            :data="this.$store.state.realGoods.tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
            style="width: 85% ;font-size:15px">
            <el-table-column prop="id" label="账号">
            </el-table-column>
            <el-table-column prop="masterId" label="雇主">
            </el-table-column>
            <el-table-column prop="name" label="菜名">
            </el-table-column>
            <el-table-column prop="status" label="状态">
                <template slot-scope="scope">
                    <span v-if="scope.row.status == 0" style="color:aqua;">启用</span>
                    <span v-if="scope.row.status == 1" style="color:brown;">禁用</span>
                </template>
            </el-table-column>
            <el-table-column prop="type" label="类型">
            </el-table-column>
            <el-table-column prop="updateTime" label="交付时间" width="200px">
            </el-table-column>
            <el-table-column label="操作" width="250px">
                <template slot-scope="scope">
                    <router-link to="/home/UPGoods">
                        <el-button size="mini" @click.native.stop="edition(scope.row.id)">
                            编辑
                        </el-button>
                    </router-link>
                    <el-button size="mini" type="danger"
                        @click.native.stop="deleteGoodsSubmit(scope.row.id)">删除</el-button>
                    <!-- <el-button size="mini" :type="scope.row.status === 1 ? '' : 'danger'"
                        @click.native.stop="ModifyStatus(scope.row.id, scope.row.status)">{{ scope.row.status == 1
                            ? '启用' : '禁用' }}</el-button> -->
                    <el-button size="mini" :type="scope.row.status === 1 ? '' : 'danger'" @click.native.stop="p()">{{
                        scope.row.status == 1
                            ? '启用' : '禁用' }}</el-button>

                </template>

            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination :current-page.sync="currentPage" @current-change="handleCurrentChange" :page-size="pageSize"
                layout="prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </el-main>
</template>

<script>
import axios from 'axios';
export default {
    data() {
        return {
            pageSize: 10,
            currentPage: 0,
            total: 0,
            pagerCount: 0,
            id: this.$store.state.realGoods.id
        }
    },
    methods: {
        p() {
            this.x.$emit('12345')
        },
        a() {
            console.log(this.$store.state.realGoods.type);
            axios({
                methods: 'get',
                url: 'http://localhost:8090/RealGoods/Subpages',
                params: {
                    type: this.$store.state.realGoods.type
                }
            }).then(res => {
                console.log(res.data);
                this.arr = res.data
                this.$store.state.realGoods.tableData = res.data
                this.tableData = this.$store.state.realGoods.tableData
                this.$store.state.realGoods.array = this.tableData
                this.array = this.$store.state.realGoods.array
                const size = this.tableData.length
                this.total = size
                this.pagerCount = size / this.pageSize
            })
        },
        handleCurrentChange(val) {
            this.currentPage = val;
        }, UpDataUser(row, column, event) {
            // 在这里调用你的方法
            console.log('dfadsfads+++++++++++++' + row.id)
            this.$router.replace({ path: '/home/UPGoods' })
            let target = this.$store.state.Goods.tableData.filter(res => {
                return res.id == row.id
            });
            console.log(target);
            this.$store.state.Goods.name = target[0].name
            this.$store.state.Goods.date = target[0].date
            this.$store.state.Goods.address = target[0].address
        },
        UpdataTotal() {
            axios.put('http://localhost:8090/RealGoods/UpdataTotal')
        },
        ModifyStatus(id1, status1) {
            console.log('fdfadsfads' + id1)
            console.log('fdafadfdaf' + status1)
            axios({
                methods: 'PUT',
                url: 'http://localhost:8090/RealGoods/ModifyUserStatus',
                params: {
                    id: id1,
                    status: status1
                }
            }).then((res) => {
                this.$message({
                    type: 'success',
                    message: '修改完成!'
                });
                this.a()
            });
        }, deleteGoodsSubmit(e1) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                axios({
                    methods: 'delete',
                    url: 'http://localhost:8090/RealGoods/DelGoods',
                    params: {
                        id: e1
                    }
                }).then((res) => {
                    console.log(res.data);
                    if (res.data.msg == null) {
                        this.a()
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        // this.x.$emit('12345', 'dasd')
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });

        },
    }, mounted() {
        this.a()
    }
}



</script>
<style lang="less" scoped>
.el-container {
    margin-left: 100px;
}

.el-dropdown {
    margin-left: 550px;

}

.el-main {
    margin-left: 50px;
}

.block {
    margin-left: 360px;
}
</style>